
/**
 * @desc 考核管理，添加考核项目弹框
 * @author yd_zhaorongjun
 */
<template>
  <div>
    <el-dialog
      title="添加考核项目"
      class="gl_dialog_TitleLine"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :before-close="close"
      width="880px"
    >
      <el-scrollbar wrap-class="scrollbar-wrapper gl_dialog_height">
        <el-form ref="AssessmentVO" class="gl_form_mini" :model="AssessmentVO" :rules="AssessmentVO_Rules" label-position="right" label-width="140px" style="padding-right: 30px;">
          <el-row :gutter="20">
            <el-col :span="12">
              <!-- 项目类别 -->
              <el-form-item label="项目类别" prop="type">
                <el-select v-model="AssessmentVO.type" placeholder="请输入项目类别" style="width:100%" size="mini">
                  <!-- <el-option label="区域一" value="shanghai"></el-option> -->
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <!-- 项目名称 -->
              <el-form-item label="项目名称" prop="assessmentName">
                <el-input v-model="AssessmentVO.assessmentName" placeholder="请输入考核项目名称" name="assessmentName" type="text" size="mini" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <!-- 成绩单位 -->
              <el-form-item label="成绩单位" prop="unit">
                <el-input v-model="AssessmentVO.unit" placeholder="请输入考核项目成绩单位（例：cm/厘米、kg/千克、次）" name="unit" type="text" size="mini" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-scrollbar>

      <span slot="footer" class="dialog-footer">
        <!-- 取消按钮 -->
        <el-button size="mini" @click="close()">{{ $t('button.cancel') }}</el-button>
        <!-- 保存按钮 -->
        <el-button v-if="type == 'new'" type="primary" size="mini" @click="saveNew()">{{ $t('button.save') }}</el-button>
        <!-- 保存按钮 -->
        <el-button v-else type="primary" size="mini" @click="saveEdit()">{{ $t('button.save') }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { AssessmentVO_Rules } from '@/lib/validate/grade/index.js';
import { AssessmentVO } from '@/lib/form/grade.js';
// import { translateByCode } from '@/lib/getTransData';

export default {
  name: 'AddAssessment',
  data() {
    return {
      AssessmentVO: new AssessmentVO(),
      AssessmentVO_Rules: new AssessmentVO_Rules(),
      dialogVisible: false,
      type: '' // 弹框状态，是新增和是修改 new 是新增，edit是修改
    };
  },
  computed: {
  },
  methods: {
    open(row) {
      // this.AssessmentVO = new VO();
      this.type = row ? 'edit' : 'new';
      console.log(row);
      this.AssessmentVO = row || new AssessmentVO();
      // this.CopyData(this.dto, this.AssessmentVO);
      this.$nextTick(() => {
        this.dialogVisible = true;
      });
    },
    // 关闭弹框
    close() {
      this.dialogVisible = false;
      this.$nextTick(() => {
        this.$refs.AssessmentVO.clearValidate();
      });
    },
    // 新增
    saveNew() {
      console.log(this.AssessmentVO);
      this.$refs.AssessmentVO.validate(valid => {
        if (!valid) return;
        this.$emit('insert', this.AssessmentVO);
      });
    },
    // 修改
    saveEdit() {
      console.log(this.AssessmentVO);
      this.$refs.AssessmentVO.validate(valid => {
        if (!valid) return;
        this.$emit('update', this.AssessmentVO);
      });
    }
  }
};
</script>

<style lang="scss">
</style>
